﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    
    class DebHelper
    {
        private static readonly string conString = "server=.;database=Blogs;uid=sa;pwd=123456";
        /// <summary>
        /// 显示数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection connection = new SqlConnection(conString);
            connection.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connection);
            DataTable dt = new DataTable();
            dataAdapter.Fill(dt);
            return dt;
        }
        /// <summary>
        /// 增加删除修改
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddOrUpDateOrDelete(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);

            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);

            sqlConnection.Open();

            return sqlCommand.ExecuteNonQuery();

        }

        
    }
}
